#include "fxcc/imgui/Editor.h"
#include "fxcc/core/audio/common/Maps.h"
#include "fxcc/core/audio/common/AudioImporter.h"
#include "fxcc/core/Dir.h"

using namespace fxcc::audio::common;
using namespace fxcc::imgui;

template <>
bool Editor::Edit<AudioClipMap>(const std::string& label, AudioClipMap& e)
{
    bool flag{ 0 };
	bool combo = ImGui::BeginCombo(label.c_str(), e.m_Index.m_Name.c_str());

	if (combo)
	{

		for (const auto& [key, value] : AudioImporter::m_AudioMetaData.m_AudioMetaCaches)
		{
			ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 1.0f, 0.5f, 1.0f));
			ImGui::Text(key.c_str());
			ImGui::PopStyleColor();

			for (const auto& value2 : value.m_Audios)
			{
				ImGui::PushID(&value2);
				const std::string& itemLabel = value2.m_Name;
				bool selectable = ImGui::Selectable(itemLabel.c_str(), e.m_Index.m_FileId == value2.m_FileId);
				if (selectable)
				{
					e.m_Index = value2;
				}
				ImGui::PopID();
			}
		}

		ImGui::EndCombo();
	}

    if (ImGui::Button("Play"))
    {
        if (e.m_Value)
            e.m_Value->Play();
    }
    ImGui::SameLine();
    if (ImGui::Button("Pause"))
    {
        if (e.m_Value)
            e.m_Value->Pause();
    }   
    ImGui::SameLine();
    if (ImGui::Button("Stop"))
    {
        if (e.m_Value)
            e.m_Value->Stop();
    }
    ImGui::SameLine();

    return flag;
}